import { login } from "@/commonApi"
import VueCookies from "vue-cookies"
export default {
	state:()=>({
		isLogin:false,
		userInfo:{}
	}),
	mutations: {
		commitUserinfo(state,userInfo){
			state.userInfo = userInfo
			if(userInfo.token){
				state.isLogin = true
				VueCookies.set('Authorization',userInfo.token,8640)
				VueCookies.set('isLogin',state.isLogin,8640)
			}
		}
	},
	actions: {
		asyncLogin({commit},params){
			return  login(params).then((data)=>{
						commit('commitUserinfo',data)
						return Promise.resolve()
					}).catch((err)=>{
						return Promise.reject(err)
					})
		}
	}
}
